package com.osce.score.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csce.domain.entity.score.ScoreExExamTime;
import com.doudou.core.container.ListUtil;
import com.osce.interfaces.score.IScoreExExamTimeService;
import com.osce.score.mapper.ScoreExExamTimeMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 考试时间段Service业务层处理
 *
 * @author zzx
 * @since 2023-09-05
 */
@Service
public class ScoreExExamTimeServiceImpl extends ServiceImpl<ScoreExExamTimeMapper, ScoreExExamTime> implements IScoreExExamTimeService {

    /**
     * 查询考试时间段
     *
     * @param id 考试时间段主键
     * @return 考试时间段
     */
    @Override
    public ScoreExExamTime selectScoreExExamTimeById(Long id) {
        return baseMapper.selectScoreExExamTimeById(id);
    }

    /**
     * 查询考试时间段列表
     *
     * @param scoreExExamTime 考试时间段
     * @return 考试时间段
     */
    @Override
    public List<ScoreExExamTime> selectScoreExExamTimeList(ScoreExExamTime scoreExExamTime) {
        return baseMapper.selectScoreExExamTimeList(scoreExExamTime);
    }

    /**
     * 新增考试时间段
     *
     * @param scoreExExamTime 考试时间段
     * @return 结果
     */
    @Override
    public int insertScoreExExamTime(ScoreExExamTime scoreExExamTime) {
        return baseMapper.insertScoreExExamTime(scoreExExamTime);
    }


    /**
     * 修改考试时间段
     *
     * @param scoreExExamTime 考试时间段
     * @return 结果
     */
    @Override
    public int updateScoreExExamTime(ScoreExExamTime scoreExExamTime) {
        return baseMapper.updateScoreExExamTime(scoreExExamTime);
    }

    /**
     * 批量删除考试时间段
     *
     * @param ids 需要删除的考试时间段主键
     * @return 结果
     */
    @Override
    public int deleteScoreExExamTimeByIds(Long[] ids) {
        return baseMapper.deleteScoreExExamTimeByIds(ids);
    }

    /**
     * 删除考试时间段信息
     *
     * @param id 考试时间段主键
     * @return 结果
     */
    @Override
    public int deleteScoreExExamTimeById(Long id) {
        return baseMapper.deleteScoreExExamTimeById(id);
    }

    @Override
    public int batchInsertScoreExExamTime(List<ScoreExExamTime> scoreExExamTimes, Long examId) {
        if (ListUtil.isEmpty(scoreExExamTimes)) {
            return 0;
        }
        scoreExExamTimes = scoreExExamTimes.stream().peek(time -> time.setExamId(examId)).collect(Collectors.toList());
        return baseMapper.batchInsertScoreExExamTime(scoreExExamTimes);
    }

    @Override
    public int deleteScoreExExamTimeByExamIds(Long[] ids) {
        return baseMapper.deleteScoreExExamTimeByExamIds(ids);
    }

    @Override
    public int deleteScoreExExamTimeByExamId(Long id) {
        return baseMapper.deleteScoreExExamTimeByExamId(id);
    }

    @Override
    public Map<Long, ScoreExExamTime> selectScoreExExamTimeToMapByIds(Long[] ids) {
        return baseMapper.selectScoreExExamTimeToMapByIds(ids);
    }
}
